//该文件专门用于常见整个应用的路由器
import VueRouter from 'vue-router'

import LeftSider from '../pages/LeftSider.vue'
import Loadings from '../components/Loadings.vue'
// import cookie from '../utils/auth'
import MeProcess from '../components/StudentPlan/MeProcess.vue'
import ReleaseProcess from '../components/StudentPlan/ReleaseProccess.vue'
import ProcessTitle from '../components/StudentPlan/ProcessTitle.vue'
import MeBeforeProcess from '../components/StudentPlan/MeBeforeProcess.vue'
import ProcessContent from '../components/StudentPlan/ProcessContent.vue'
import GradesName from '../components/StudentPlan/GradesName.vue'
import AddSchedule from '../components/Schedules/AddSchedule.vue'

import PersonalAllSchedule  from '../components/Schedules/PersonalAllSchedule.vue'
import CommunalSchedule from '../components/Schedules/CommunalSchedule.vue'
//创建一个路由器
const router = new VueRouter({
    routes:[
        {
            //加载页面
            name:'Loading',
            path:'/',
            component:Loadings,
            meta:{
                title:'未来小组管理系统',
                requireAuth: false,
            }
        },
        {
            // 侧边栏
            name:'LeftSider',
            path:'/LeftSider',
            component:LeftSider,
            meta:{
                title:'未来小组管理系统',
                requireAuth: true,//需要登陆
            },
            children:[ //添加课程
                { name:'AddSchedule',
                path:'AddSchedule',
                component:AddSchedule,
               
                },
                {
                    name:'MeProcess',
                    path:'MeProcess',
                    component:MeProcess,
                    meta:{
                        title:'学习进度填写',
                        requireAuth: true,//需要登陆
                    },
                },
                {
                    name:'ReleaseProcess',
                    path:'ReleaseProcess',
                    component:ReleaseProcess,
                    meta:{
                        title:'发布学习计划',
                        requireAuth:true,
                    }
                },
                {
                    name:'ProcessTitle',
                    path:`ProcessTitle/:id/:title`,
                    component:ProcessTitle,
                    meta:{
                        title:'学习任务题目',
                        requireAuth:true,
                    },
                    // props({params:{id,title}}){
                    //     return {id,title}
                    // }
                },
                {
                    name:'MeBeforeProcess',
                    path:'MeBeforeProcess',
                    component:MeBeforeProcess,
                    meta:{
                        title:'我的学习任务',
                        requireAuth:true,
                    }
                },
                {
                    name:'ProcessContent',
                    path:'ProcessContent/:id',
                    component:ProcessContent,
                    meta:{
                        title:'学习计划内容页',
                        requireAuth:true,
                    }
                },
                {
                    name:'GradesName',
                    path:'GradesName',
                    component:GradesName,
                    meta:{
                        title:'查看各组的学习进度',
                        requireAuth:true,
                    }
                },
                {
                    name:'PersonalSchedule',
                    path:'PersonalSchedule/All',
                    component:PersonalAllSchedule,
                    meta:['首页','课表','个人课表']
               },
               {
                    name:'CommunalSchedule',
                    path:'CommunalSchedule',
                    component:CommunalSchedule,
                    meta:['首页','课表','公共课表']
                }
            ]
        },
       
    ]
})


//全局前置守卫
// router.beforeEach((to, from, next) => {
//     if (to.meta.requireAuth) {  // 判断该路由是否需要登录权限
//         if(cookie.getToken("TokenKey")!=undefined){//判断token是否存在
//             next()
//         }else{
//             window.location.href="https://passport.wlgzs.net/oauth2/authorize?redirect_uri=http://localhost:8080&client_id=36BD5461CA71D6966AA93B19F150B867&response_type=code&scope=permission%20student_id%20email%20qq_number%20avatar"
//         }
//     }else {
//         next();
//     }
// })

//全局后置_路由守卫
router.afterEach((to)=>{
    document.title = to.meta.title || "未来小组管理系统"
})


export default router